package com.devin.service.Impl;

import com.devin.dao.MultiMapper;
import com.devin.dao.PermissionMapper;
import com.devin.pojo.Permission;
import com.devin.service.PermissionService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("permissionService")
@Transactional
public class PermissionServiceImpl implements PermissionService {
    @Autowired
    private PermissionMapper permissionMapper;

    @Autowired
    private MultiMapper multiMapper;

    @Override
    public List<Permission> getPermissions() {
        return permissionMapper.getPermissions();
    }

    @Override
    public List<Permission> getPermissionsByPage(Integer page,Integer size) {
        PageHelper.startPage(page,size);
        return permissionMapper.getPermissions();
    }

    @Override
    public void addPermission(Permission permission) {
        permissionMapper.addPermission(permission);
    }

    @Override
    public void delPermission(Integer permissionId) {
        permissionMapper.delRoleAndPermission(permissionId);
        permissionMapper.delPermission(permissionId);
    }

    @Override
    public List<Permission> getPermissions2Json(Integer roleId) {
        List<Permission> permissions = permissionMapper.getPermissions2Json(roleId);
        return permissions;
    }

    @Override
    public void delPermissionsChecked(Integer[] ids) {
        multiMapper.delPermissionsCheckedByPermissionId(ids);
        multiMapper.delPermissionsChecked(ids);
    }

    @Override
    public List<Permission> getPermissionsAndRoles() {
        List<Permission> permissions =permissionMapper.getPermissionsAndRoles();
        return permissions;
    }


}
